#!/bin/bash
#
# Pre-push hook verifying that inappropriate code will not be pushed.

# Colors for the terminal output
RED='\033[0;31m'
NC='\033[0m' # No Color

# Common prompts
INSTALL_PROPT="Please install ZK Stack CLI using zkstackup from https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/zkstackup"
FORMAT_PROMPT="Please format the code via 'zkstack dev fmt', cannot push unformatted code"

# Check that prettier formatting rules are not violated.
if which zkstack >/dev/null; then
  if ! zkstack dev fmt --check; then
      echo -e "${RED}Push error!${NC}"
      echo -e "${FORMAT_PROMPT}"
      exit 1
  fi
else
  if which zk_supervisor >/dev/null; then
    echo -e "${RED}WARNING: zkup, zk_inception/zki, and zk_supervisor/zks are DEPRECATED.${NC}"
    echo -e "${RED}${INSTALL_PROPT}${NC}"

    if ! zk_supervisor fmt --check; then
      echo -e "${RED}Push error!${NC}"
      echo -e "${FORMAT_PROMPT}"
      exit 1
    fi
  else
    echo -e "${INSTALL_PROPT}"
    exit 1
  fi
fi
